const app = getApp();

Page({
  input: app.input,
  phone: app.phone,
  /**
   * 页面的初始数据
   */
  data: {
    name:"",
    phone: "",
    fee: "",
    mrRoom: wx.getStorageSync('mrRoom'),
    data:{},
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    app.init(this);
    
    this.setData({
      mrRoom: wx.getStorageSync('mrRoom'),
    })
    
    let mrRoom = wx.getStorageSync("mrRoom")
    app.api.client_propertyBill_getPropertyBillRechargeShowData({
      token: wx.getStorageSync("token"),
      idRoom: mrRoom.idRoom,
    }, (res) => {
      console.log(res)
      this.setData({
        data: res.data,
      })
    })
   

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  client_propertyBill_payPropertyBillRecharge: function () {
    let mrRoom = wx.getStorageSync("mrRoom")
    app.api.client_propertyBill_payPropertyBillRecharge({
      token: wx.getStorageSync("token"),
      idRoom: mrRoom.idRoom,
      name: this.data.name,
      phone: this.data.phone,
      fee: this.data.fee,
      
    }, (res) => {
      if(res.status ==-1){
        app.toast(res.msg);
        return false;
      }

      wx.requestPayment({
        timeStamp: String(res.data.timeStamp),
        nonceStr: res.data.nonce_str,
        package: res.data.prepay_id,
        signType: "MD5",
        paySign: res.data.sign,
        success(res) {
          console.log("支付调用结果=>", res);
          app.toast("支付成功");
          wx.navigateBack()
        },
        fail(res) {
          console.log("支付调用结果 fail=>", res);
          app.toast("支付取消");
        }
      });

    })

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})